Added gdk_pixbuf_copy_area() to gdk-pixbuf-utils.c and gdk-pixbuf.h.
authorCody Russell <bratsche@src.gnome.org>
Thu, 13 Jan 2000 07:24:49 +0000 (07:24 +0000)
committerCody Russell <bratsche@src.gnome.org>
Thu, 13 Jan 2000 07:24:49 +0000 (07:24 +0000)
Removed some unused variable warnings in gdk-pixbuf-drawable.c.

demos/testpixbuf-drawable.c
gdk-pixbuf/gdk-pixbuf-util.c
gdk-pixbuf/gdk-pixbuf.h

index 0ac321e237d351610daf20be06c9d78105d705e2..3d43244ca5545710f1d9e5f249e38ee3e8ccbb61 100644 (file)
@@ -12,7 +12,6 @@ void expose_cb(GtkWidget *drawing_area, GdkEventExpose *evt, gpointer
 data)
 {
    GdkPixbuf *pixbuf;
-   gint x1, y1, x2, y2;
          
    pixbuf = (GdkPixbuf *) gtk_object_get_data(GTK_OBJECT(drawing_area),
                                               "pixbuf");
@@ -44,10 +43,11 @@ data)
                          pixbuf->art_pixbuf->rowstride);
    }
 }
+
 void configure_cb(GtkWidget *drawing_area, GdkEventConfigure *evt,
 gpointer data)
 {
-   GdkPixbuf *pixbuf, spb;
+   GdkPixbuf *pixbuf;
                            
    pixbuf = (GdkPixbuf *) gtk_object_get_data(GTK_OBJECT(drawing_area),   
                                               "pixbuf");
@@ -67,8 +67,6 @@ int main(int argc, char **argv)
    GtkWidget     *vbox;
    GtkWidget     *drawing_area;
    GdkPixbuf     *pixbuf;    
-   gint           width, height;
-   gint           x, y;
    
    gtk_init(&argc, &argv);   
    gdk_rgb_set_verbose(TRUE);
index b507d25070e25576e052a08b8041069dd29ae6af..2bc7e98b06f165ac74b2b7d14bf6d84d0fcbaee5 100644 (file)
@@ -2,7 +2,8 @@
  *
  * Copyright (C) 1999 The Free Software Foundation
  *
- * Author: Federico Mena-Quintero <federico@gimp.org>
+ * Authors: Federico Mena-Quintero <federico@gimp.org>
+ *          Cody Russell  <bratsche@dfw.net>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -93,3 +94,61 @@ gdk_pixbuf_add_alpha (GdkPixbuf *pixbuf, gboolean substitute_color, guchar r, gu
 
        return new_pixbuf;
 }
+
+/**
+ * gdk_pixbuf_copy_area:
+ * @src_pixbuf: The pixbuf to be copied.
+ * @src_x: The X coordinate of the upper left corner of the area to copy.
+ * @src_y: The Y coordinate of the upper left corner of the area to copy.
+ * @width: The width of the area to copy.
+ * @height: The height of the area to copy.
+ * @dest_pixbuf: The pixbuf to store the copy in.
+ * @dest_x: X coordinate for the upper left corner of the rectangle to draw to in @dest_pixbuf.
+ * @dest_y: Y coordinate for the upper left corner of the rectangle to draw to in @dest_pixbuf.
+ *
+ * Takes a rectangle area beginning at (@src_x, @src_y) @width pixels wide
+ * and @height pixels high from @src_pixbuf and copy it into @dest_pixbuf
+ * at (@dest_x, @dest_y). @dest_pixbuf must already be created and must be
+ * large enough to hold the requested area.
+ *
+ * Return value: void
+ **/
+void gdk_pixbuf_copy_area(GdkPixbuf *src_pixbuf,
+                         gint src_x, gint src_y,
+                         gint width, gint height,
+                         GdkPixbuf *dest_pixbuf,
+                         gint dest_x, gint dest_y)
+{
+       gint src_width, src_height, dest_width, dest_height;
+
+       /* Ensure that we have a source pixbuf, and that the requested
+        * area is not larger than that pixbuf.
+        */
+       g_return_if_fail(src_pixbuf != NULL);
+
+       src_width = gdk_pixbuf_get_width(src_pixbuf);
+       src_height = gdk_pixbuf_get_height(src_pixbuf);
+
+       g_return_if_fail(src_x >= 0 && width <= src_width);
+       g_return_if_fail(src_y >= 0 && height <= src_height);
+
+       /* Ensure that we have a destination pixbuf, and that the
+        * requested area is not larger than that pixbuf.
+        */
+       g_return_if_fail(dest_pixbuf != NULL);
+
+       dest_width = gdk_pixbuf_get_width(dest_pixbuf);
+       dest_height = gdk_pixbuf_get_height(dest_pixbuf);
+
+       g_return_if_fail(dest_x >= 0 && width <= dest_width);
+       g_return_if_fail(dest_y >= 0 && height <= dest_height);
+
+       /* Scale 1:1 the source pixbuf into the destination pixbuf. */
+       gdk_pixbuf_scale(src_pixbuf,
+                        dest_pixbuf,
+                        dest_x, dest_y,
+                        width, height,
+                        (double)(dest_x - src_x),
+                        (double)(dest_y - src_y),
+                        1., 1., ART_FILTER_NEAREST);
+}
index 82784c3023b36622faed732605faa9a71031c239..91898c1eec758f4bff714bbcc143bb10f2c98718 100644 (file)
@@ -163,6 +163,13 @@ GdkPixbuf *gdk_pixbuf_get_from_drawable (GdkPixbuf *dest,
                                         int dest_x, int dest_y,
                                         int width, int height);
 
+/* Copy an area of a pixbuf into another one */
+void gdk_pixbuf_copy_area (GdkPixbuf *src_pixbuf,
+                          gint src_x, gint src_y,
+                          gint width, gint height,
+                          GdkPixbuf *dest_pixbuf,
+                          gint dest_x, gint dest_y);
+
 /* Scaling */
 
 void gdk_pixbuf_scale           (GdkPixbuf      *src,